package service.Impl;


import common.result.TaotaoResult;
import dao.SearchDao;
import mapper.ItemSearchMapper;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.SearchService;


@Service
public class SearchServiceImpl implements SearchService {

	@Autowired
	private SearchDao dao;
	
	@Autowired
	private ItemSearchMapper mapper;

	@Autowired
	private SolrServer solrServer;

	@Override
	public TaotaoResult search(String query, int page, int rows) throws Exception {
		// TODO Auto-generated method stub
		SolrQuery solrQuery = new SolrQuery();
		solrQuery.hashCode();
		solrQuery.setQuery(query);
		solrQuery.setStart((page - 1) * rows);
		solrQuery.setRows(rows);
		solrQuery.set("df", "report_keywords");
		return dao.search(solrQuery);
	}
	
	@Override
	public TaotaoResult importData() {
//		try {
//
////			List<SearchItem> list = mapper.getAll();
////			for (SearchItem item : list) {
////				SolrInputDocument document = new SolrInputDocument();
////				document.setField("id", item.getId());
////				document.setField("item_title", item.getTitle());
////				document.setField("item_sell_point", item.getSell_point());
////				document.setField("item_price", item.getPrice());
////				document.setField("item_image", item.getImage());
////				document.setField("item_category_name", item.getCategory_name());
////				document.setField("item_desc", item.getItem_desc());
////				solrServer.add(document);
////			}
////			solrServer.commit();
////			return new TaotaoResult().ok();
////		} catch (Exception e) {
////			e.printStackTrace();
//			return new TaotaoResult();
//
//		}
		return new TaotaoResult();
	}
	

	

}
